<?php
require_once('App-Top.php');
require_once('Cookie-Handler.php'); //// Only Activate in UNProtected Area
////require_once('Authorizer.php'); //// Only Activate in Protected Area
require_once('FEFunctions.php');
//// index.php
//// This is the Main Page for the WOG site.

//// Set Page Title
$page_title = 'Welcome to Whiff Of Grape - Home';
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title><?php echo $page_title; ?></title>
        <style type="text/css" media="screen">@import url(style.css);</style>
    </head>

<body>
    <div id="bigWrapper">

        <div id="wrapper">

            <div id="header">
            </div>

            <div id="sidebar">

                <?php
                    require_once('MenuLeft.php');
                ?>

            </div>

            <!-- End of Header & Start Content -->

            <div id="body">

                <div id="entryTitlePage">Welcome to Whiff Of Grape</div>


                <?php
                require_once(MYSQL);
                require_once(STATEM_MYSQL);
                require_once('FEFunctions.php');
                require_once('ShowEventsFunctions.php');

                //// Query for the Upcoming/Blocked Event
                $qEventsUpcomingBlocked = sprintf($Q_ALL_NONE_Events_StatusUorB);
                $rEventsUpcomingBlocked = mysqli_query($dbc, $qEventsUpcomingBlocked) or trigger_error("Query: $qEventsUpcomingBlocked\n<br />MySQL Error: " . mysqli_error($dbc));

                $numRowsEventsUB = mysqli_num_rows($rEventsUpcomingBlocked);

                // Start showing Upcoming Events
                if ($numRowsEventsUB == 1)
                    echo '<h1 class="timingEvents">Upcoming Event</h1>';
                else
                    echo '<h1 class="timingEvents">Upcoming Events</h1>';

                if ($numRowsEventsUB >= 1)
                {
                    // Contains the information of each Event that is set as Upcoming/Blocked
                    $arrayEventsUB;
                    $indexRows = 0;
                    while ($indexRows < $numRowsEventsUB)
                    {
                        $arrayEventsUB[] = mysqli_fetch_array ($rEventsUpcomingBlocked, MYSQLI_ASSOC);
                        $indexRows++;
                    }

                    // Printing each Upcoming Event
                    $indexRows = 0;
                    foreach ($arrayEventsUB as $rowEventsUB)
                    {

                        // printingFunction
                        $userInfoRSVP = NULL;
                        if (isset($_SESSION['SESS_USER_EMAIL_FE_ID'])) {
                            if (isValid('email', $_SESSION['SESS_USER_EMAIL_FE_ID'])) {
                                $userInfoRSVP = $_SESSION['SESS_USER_EMAIL_FE_ID'];
                            }
                        }

                        // Display the event formatted
                        showIndexEvents($rowEventsUB, $userInfoRSVP, 'U' );

                        $indexRows++;
                        if ($numRowsEventsUB > $indexRows)
                        {
                            echo '<div class="timingEventsLineInner"></div>';
                        }
                    }

                }
                else
                {
                    //// Events set as Upcoming/Blocked.
                    echo '<p class="entrybodybold">Currently, there are not any Upcoming Events.</p>';
                     echo '<p class="entrybodybold">Please, visit us later.</p>';
                }

                mysqli_free_result($rEventsUpcomingBlocked);

                echo '<div class="timingEventsLineOuterUp"></div>';
                echo '<div class="timingEventsLineOuterDown"></div>';


                //// Get Today Date
                $todayDate = getdate();
                $todaySqlDate = $todayDate['year'] . '-' . $todayDate['mon'] . '-' . $todayDate['mday'];



                //// Query for the Future Event
                $qEventsFuture = sprintf($Q_ALL_NONE_EventsFuture_Date, $todaySqlDate);
                $rEventsFuture = mysqli_query($dbc, $qEventsFuture) or trigger_error("Query: $qEventsFuture\n<br />MySQL Error: " . mysqli_error($dbc));

                $numRowsEventsFuture = mysqli_num_rows($rEventsFuture);

                // Start showing Upcoming Events
                if ($numRowsEventsFuture == 1)
                    echo '<h1 class="timingEvents">Future Event</h1>';
                else
                    echo '<h1 class="timingEvents">Future Events</h1>';

                if ($numRowsEventsFuture >= 1)
                {
                    // Contains the information of each Event that is set as Upcoming/Blocked
                    $arrayEventsFuture;
                    $indexRows = 0;
                    while ($indexRows < $numRowsEventsFuture)
                    {
                        $arrayEventsFuture[] = mysqli_fetch_array ($rEventsFuture, MYSQLI_ASSOC);
                        $indexRows++;
                    }

                    // Printing each Upcoming Event
                    $indexRows = 0;
                    foreach ($arrayEventsFuture as $rowEventsFuture)
                    {

                        // Display the event formatted
                        showIndexEvents($rowEventsFuture, NULL, 'S');

                        $indexRows++;
                        if ($numRowsEventsFuture > $indexRows)
                        {
                            echo '<div class="timingEventsLineInner"></div>';
                        }
                    }

                }
                else
                {
                    //// Events set as Upcoming/Blocked.
                    echo '<p class="entrybodybold">Currently, there are not any Future Events.</p>';
                    echo '<p class="entrybodybold">Please, visit us later.</p>';
                }

                mysqli_free_result($rEventsFuture);

                
                echo '<div class="timingEventsLineOuterUp"></div>';
                echo '<div class="timingEventsLineOuterDown"></div>';



                //// Query for the Past Event
                $qEventsPast = sprintf($Q_ALL_NONE_EventsPast_Date, $todaySqlDate);
                $rEventsPast = mysqli_query($dbc, $qEventsPast) or trigger_error("Query: $qEventsPast\n<br />MySQL Error: " . mysqli_error($dbc));

                $numRowsEventsPast = mysqli_num_rows($rEventsPast);

                // Start showing Upcoming Events
                if ($numRowsEventsPast == 1)
                    echo '<h1 class="timingEvents">Past Event</h1>';
                else
                    echo '<h1 class="timingEvents">Past Events</h1>';

                if ($numRowsEventsPast >= 1)
                {
                    // Contains the information of each Event that is set as Upcoming/Blocked
                    $arrayEventsPast;
                    $indexRows = 0;
                    while ($indexRows < $numRowsEventsPast)
                    {
                        $arrayEventsPast[] = mysqli_fetch_array ($rEventsPast, MYSQLI_ASSOC);
                        $indexRows++;
                    }

                    // Printing each Upcoming Event
                    $indexRows = 0;
                    foreach ($arrayEventsPast as $rowEventsPast)
                    {

                        // Display the event formatted
                        showIndexEvents($rowEventsPast, NULL, 'S');

                        $indexRows++;
                        if ($numRowsEventsPast > $indexRows)
                        {
                            echo '<div class="timingEventsLineInner"></div>';
                        }
                    }

                }
                else
                {
                    //// Events set as Upcoming/Blocked.
                    echo '<p class="entrybodybold">Currently, there are not any Past Events.</p>';
                    echo '<p class="entrybodybold">Please, visit us later.</p>';
                }

                mysqli_free_result($rEventsPast);


                

                mysqli_close($dbc);

                ?>


            </div> <!-- Closes body -->

            <!-- End of Content & Start Footer -->

            <div id="footer">

                <?php
                //// Includer Footer
                include ('footer.php');
                ?>

            </div>

        </div> <!-- Closes Wrapper -->
    </div> <!-- Closes bigWrapper -->
</body>
</html>
<?php
require_once('App-End.php');
?>

<!-- Designed & Developed By Jose Trujillo (2011) -->